package com.itheima.jingjie.TreeSet集合;

import java.util.Comparator;
import java.util.TreeSet;

public class StringComparator {
    public static void main(String[] args) {
        TreeSet<String> set = new TreeSet<String>(new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                int x = o1.length() - o2.length() ;

                return x != 0 ? x : (o1.compareTo(o2));
            }
        });
        set.add("aaa");
        set.add("ab");
        set.add("aaaa");
        set.add("abb");
        set.add("abac");
        set.add("abbb");
        for (String s : set) {
            System.out.println(s);
        }

    }
}
